<?php
	
	/**
	 * @处理输出的内容,达到美观好看
	 * author: liuricheng
	 * time:2013-07-19
	 *
	 */
	function t($array){
		$test = debug_backtrace();
		$t = $test[0];
		echo "<pre><b class='debug'>[TS]:{$t['file']} line:{$t['line']}</b><br>";
		print_r($array);
		echo "</pre>"; 
	}

	/**
	 * @递归排序
	 * author:liuricheng
	 * time:2013-07-20
	 * 
	 */
	function catsort($arr,$parent_id = 0,$lev = 1){
		static $list = array();
		foreach ($arr as $v){
			if($v['parent_id'] == $parent_id){
				$v['lev']  = $lev;
				$list[] = $v;
				catsort($arr,$v['cat_id'],$lev +1);
			}
		}
		return $list;
	}
	
	/**
	 * @在不同级别的分类前加上空白符
	 * @处理缩进
	 * author:liuricheng
	 * time:2013-07-20
	 * 
	 */
	function addWhiteSpace($datas){
		$catList = array();
		foreach($datas as $n=>$v){
			$v['cat_name']    =    str_repeat("&nbsp;&nbsp;&nbsp;",$v['lev']).$v['cat_name'];
			$catList[]        =    $v;
		}
		return $catList;
	}
	
	/**
	 * 输出换行符
	 * @abstract:方便测试使用
	 * @param:count(int)
	 * 
	 */
	function br($count = 0){
		if(0 == $count) return;
		for($i = 0; $i < $count ; $i ++){
			echo "</br>";
		}
	}
	
	/**
	 * 随机生成验证码
	 * @
	 *
	 */
	function createVerifyCode($length = 6){
		$str = '012346578901234567890123456789012346789';
		$randNum = ''; 
		for($i=0;$i<$length;$i++){
			$randNum .= substr($str,mt_rand(0,strlen($str)-1),1);
		}

		$_SESSION['code']	=	$randNum;		
		return $randNum;
	}
	
	/**
	 * 随机生成用户名
	 * @abstract:生成的用户名长度为9
	 * @param 	prex 	用户名前缀
	 * @param	length	用户名长度
	 * 
	 */
	function createUserName($prex = 'ybr_',$length = 6){		
		$time = time();
		$str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
		$randNum = ''; 
		for($i=0;$i<4;$i++){
			$randNum .= substr($str,mt_rand(0,strlen($str)-1),1);
		}	
		$user_name = $randNum . substr($time, 5,strlen($time));
		return $user_name;
	}
	
	
		
		
	 
	
	
	



?>